
variable "rrs" { type = list }
variable "values" { type = list }
variable "zone" { type = string }
variable "alicloud_zone_id" { type = string }
variable "type" { type = string }
variable "remark" { type = string }
variable "ttl" {
  type = number
  default = 60
}

locals {
  dynamic_records = [
    for rr in var.rrs: [
      for val in var.values:
        { "rr": rr, "value": val }
    ]
  ]
}

resource "alicloud_pvtz_zone_record" "main" {
  zone_id = var.alicloud_zone_id

  type  = var.type
  ttl   = var.ttl
  remark = var.remark

  for_each = {for record in local.dynamic_records.0: format("%s/%s", record.rr, record.value) => record}
  value = each.value.value
  rr = lower(each.value.rr)
}

resource "deeproute_dns_record" "main" {
  zone  = var.zone
  type  = var.type
  ttl   = var.ttl

  for_each = {for record in local.dynamic_records.0: format("%s/%s", record.rr, record.value) => record}
  value = each.value.value
  rr = each.value.rr
}
